package com.boot.main.service.impl;

import com.boot.main.entity.BcomCategory;
import com.boot.main.entity.BcomSiteCategory;
import com.boot.main.mapper.BcomCategoryMapper;
import com.boot.main.mapper.BcomSiteCategoryMapper;
import com.boot.main.response.ResponseData;
import com.boot.main.response.ResponseDataUtil;
import com.boot.main.service.IBlogCategoryService;
import com.boot.main.service.IBlogSiteCategoryService;
import com.boot.main.utils.IsNotEmptyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class BlogSiteCategoryService implements IBlogSiteCategoryService {
    @Resource
    private BcomSiteCategoryMapper siteCategoryMapper;

    @Override
    public ResponseData getSiteCategorys(Integer status){
        List<BcomSiteCategory> items = siteCategoryMapper.getSiteCategorys(status);
        return ResponseDataUtil.success("获取分类成功", items);
    }

    @Override
    public ResponseData saveSiteCategory(BcomSiteCategory category){
        category.setCreate_time(new Date().getTime());
        Integer num = siteCategoryMapper.saveSiteCategory(category);
        if(IsNotEmptyUtil.isEmpty(num)){
            return ResponseDataUtil.error("保存分类失败", null);
        }
        return ResponseDataUtil.success("保存分类成功", null);
    }

    @Override
    public ResponseData updateSiteCategory(BcomSiteCategory category){
        category.setCreate_time(new Date().getTime());
        Integer num = siteCategoryMapper.updateSiteCategory(category);
        if(IsNotEmptyUtil.isEmpty(num)){
            return ResponseDataUtil.error("修改分类失败", null);
        }
        return ResponseDataUtil.success("修改分类成功", null);
    }

    @Override
    public ResponseData deleteSiteCategory(Long id){
        Integer num = siteCategoryMapper.deleteSiteCategory(id);
        return ResponseDataUtil.success("删除分类成功", null);
    }
}
